/**
 *  @file Primitive.h
 */
#ifndef _PRIMITIVE_H_
#define _PRIMITIVE_H_

#include "../common/BaseObject.h"

namespace cppflib
{

namespace lang
{

/**
 *  Specializations for this function reside in Primitive.cpp
 */
template <class ORGTYPE>
u32_t GenHashByType(ORGTYPE value);

/**
 *  A template class for primitive types (int, short, char, ...)
 */
template <class ORGTYPE>
class PrimitiveType : public BaseObject
{
private:
    ORGTYPE value;

    PrimitiveType()
    {
    }

public:
    explicit PrimitiveType(ORGTYPE value)
    { 
       this->value = value; 
    }

    virtual ~PrimitiveType() 
    { 
    }

    void Set(ORGTYPE value)
    {
       this->value = value;
    }

    ORGTYPE Value() const
    {
       return this->value;
    }

    virtual bool Equals(const BaseObject &obj) const
    {
       if (!this->EqualType(obj))
          return false;

       const PrimitiveType<ORGTYPE> * pTemp = static_cast<const PrimitiveType<ORGTYPE>*>(&obj);
       return this->value == pTemp->Value();
    }

    virtual u32_t GetHash(void) const
    {
       return GenHashByType<ORGTYPE>(this->value);
    }
};


/*
 *  typedef for the primitive types
 */

typedef PrimitiveType<char> Char;
typedef PrimitiveType<u8_t> Byte;
typedef PrimitiveType<wc_t> WChar;
typedef PrimitiveType<short> Short;
typedef PrimitiveType<u16_t> UShort;
typedef PrimitiveType<int> Int32;
typedef PrimitiveType<u32_t> UInt32;
typedef PrimitiveType<bool> Boolean;
typedef PrimitiveType<i64_t> Int64;
typedef PrimitiveType<u64_t> UInt64;
typedef PrimitiveType<float> Float;
typedef PrimitiveType<double> Double;
typedef PrimitiveType<ptrany_t> Ptr;



}  // end of namespace lang

}  // end of namespace cppflib


#endif
